<template>
  <el-card class="box-card">
    <div slot="header" class="clearfix">
      <span>合同签约信息录入</span>
      <el-button type="default" @click="goBack">返回</el-button>
    </div>
    <el-form
      :model="ruleForm"
      :rules="rules"
      ref="ruleForm"
      label-position="left"
      label-width="100px"
      class="demo-ruleForm"
    >
      <el-form-item label="甲方" prop="people">
        <el-input v-model="ruleForm.people" placeholder="雇主"></el-input>
      </el-form-item>
      <el-form-item label="身份证" prop="peopleNo">
        <el-input v-model="ruleForm.peopleNo"></el-input>
      </el-form-item>
      <el-form-item label="乙方" prop="user">
        <el-input v-model="ruleForm.user" placeholder="居间服务商"></el-input>
      </el-form-item>
      <el-form-item label="企业识别码" prop="userNo">
        <el-input v-model="ruleForm.userNo"></el-input>
      </el-form-item>
      <el-form-item label="服务地址" prop="address">
        <el-input
          type="textarea"
          v-model="ruleForm.address"
          :autosize="{ minRows: 4, maxRows: 6}"
          placeholder="电话选填"
        ></el-input>
      </el-form-item>
      <el-form-item label="签约日期" prop="day">
        <el-date-picker type="date" v-model="ruleForm.day" style="width: 100%"></el-date-picker>
      </el-form-item>
      <el-divider></el-divider>
      <span>服务内容</span>
      <el-divider></el-divider>
      <el-form-item label="服务类型" prop="type">
        <el-radio-group v-model="ruleForm.type">
          <el-radio label="住家"></el-radio>
          <el-radio label="不住家"></el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="工作内容" prop="work">
        <el-checkbox-group v-model="ruleForm.work">
          <el-checkbox label="普通家务" name="work"></el-checkbox>
          <el-checkbox label="婴幼儿护理" name="work"></el-checkbox>
          <el-checkbox label="孕产妇护理" name="work"></el-checkbox>
          <el-checkbox label="老人陪护" name="work"></el-checkbox>
          <el-checkbox label="病残介护" name="work"></el-checkbox>
          <el-checkbox label="钟点工" name="work"></el-checkbox>
        </el-checkbox-group>
        <el-input
          type="textarea"
          v-model="ruleForm.other"
          :autosize="{ minRows: 4, maxRows: 6}"
          placeholder="其他服务内容"
        ></el-input>
      </el-form-item>
      <el-divider></el-divider>
      <span>约定事项</span>
      <el-divider></el-divider>
      <el-form-item label="入户时间" prop="date">
        <el-date-picker type="date" placeholder="选择日期" v-model="ruleForm.date" style="width: 100%"></el-date-picker>
      </el-form-item>
      <el-form-item prop="time">
        <el-time-picker placeholder="选择时间" v-model="ruleForm.time" style="width: 100%"></el-time-picker>
      </el-form-item>
      <el-form-item label="工资标准" prop="wage">
        <el-input type="number" v-model="ruleForm.wage">
          <template slot="prepend">￥</template>
          <template slot="append">元</template>
        </el-input>
      </el-form-item>
      <el-form-item label="休息制度" prop="rest">
        <el-input type="textarea" :autosize="{ minRows: 4, maxRows: 6}" v-model="ruleForm.rest"></el-input>
      </el-form-item>
      <el-divider></el-divider>
      <span>服务费用</span>
      <el-divider></el-divider>
      <el-form-item label="居间服务费" prop="money">
        <el-input v-model="ruleForm.money" type="number">
          <template slot="prepend">￥</template>
          <template slot="append">元</template>
        </el-input>
      </el-form-item>
      <el-form-item label="费用标准" prop="standard">
        <el-radio-group v-model="ruleForm.standard">
          <el-radio label="家政员月工资X0.2"></el-radio>
          <el-radio label="家政员月工资X0.3"></el-radio>
          <el-radio label="家政员月工资X0.5"></el-radio>
          <el-radio label="短期工信息服务费面议"></el-radio>
        </el-radio-group>
      </el-form-item>
      <el-divider></el-divider>
      <span>委托购买意外伤害保险</span>
      <el-divider></el-divider>
      <el-form-item label="是否购买" prop="buy">
        <el-radio-group v-model="ruleForm.buy">
          <el-radio label="同意"></el-radio>
          <el-radio label="拒绝"></el-radio>
        </el-radio-group>
      </el-form-item>
      <el-divider></el-divider>
      <el-row class="sub-btn">
        <el-button @click="resetForm('ruleForm')">重置</el-button>
        <el-button type="primary" @click="submitForm('ruleForm')">提交</el-button>
      </el-row>
    </el-form>
  </el-card>
</template>

<script>
export default {
  name: "Signing",
  data() {
    return {
      ruleForm: {
        // 甲方
        people: "",
        // 身份证
        peopleNo: "",
        // 乙方
        user: "",
        // 企业识别码
        userNo: "",
        // 服务地址
        address: "",
        // 签约日期
        day: "",
        // 服务类型
        type: "",
        // 工作内容
        work: [],
        // 其他服务内容
        other: "",
        // 入户日期
        date: "",
        // 入户时间
        time: "",
        // 工资标准
        wage: "",
        // 休息制度
        rest: "",
        // 居间服务费
        money: "",
        // 费用标准
        standard: "",
        // 保险购买
        buy: ""
      },
      rules: {
        people: [
          { required: true, message: "请输入雇主姓名", trigger: "blur" },
          { min: 2, max: 4, message: "长度在 2 到 4 个字符", trigger: "blur" }
        ],
        peopleNo: [
          { required: true, message: "请输入身份证号码", trigger: "blur" },
          {
            min: 15,
            max: 18,
            message: "长度在 15 到 18 个字符",
            trigger: "blur"
          }
        ],
        user: [
          { required: true, message: "请输入居间服务商", trigger: "blur" }
        ],
        userNo: [
          { required: true, message: "请输入企业识别码", trigger: "blur" }
        ],
        address: [
          { required: true, message: "请输入服务地址", trigger: "blur" }
        ],
        day: [
          {
            type: "date",
            required: true,
            message: "请选择签约日期",
            trigger: "change"
          }
        ],
        type: [
          { required: true, message: "请选择服务类型", trigger: "change" }
        ],
        work: [
          {
            type: "array",
            required: true,
            message: "请至少选择一个工作内容",
            trigger: "change"
          }
        ],
        date: [
          {
            type: "date",
            required: true,
            message: "请选择入户日期",
            trigger: "change"
          }
        ],
        time: [
          {
            type: "date",
            required: true,
            message: "请选择入户时间",
            trigger: "change"
          }
        ],
        wage: [{ required: true, message: "请输入工资金额", trigger: "blur" }],
        rest: [{ required: true, message: "请输入休息制度", trigger: "blur" }],
        money: [
          { required: true, message: "请输入服务费用金额", trigger: "blur" }
        ],
        standard: [
          { required: true, message: "请选择费用标准", trigger: "change" }
        ],
        buy: [
          {
            required: true,
            message: "请选择是否委托购买保险",
            trigger: "change"
          }
        ]
      }
    };
  },
  methods: {
    goBack() {
      this.$router.go(-1);
    },
    submitForm(formName) {
      this.$refs[formName].validate(valid => {
        if (valid) {
          let params = new URLSearchParams();
          params.append("people", this.ruleForm.people);
          params.append("peopleNo", this.ruleForm.peopleNo);
          params.append("user", this.ruleForm.user);
          params.append("userNo", this.ruleForm.userNo);
          params.append("address", this.ruleForm.address);
          params.append("day", this.ruleForm.day);
          params.append("type", this.ruleForm.type);
          params.append("work", this.ruleForm.work);
          params.append("other", this.ruleForm.other);
          params.append("date", this.ruleForm.date);
          params.append("time", this.ruleForm.time);
          params.append("wage", this.ruleForm.wage);
          params.append("rest", this.ruleForm.rest);
          params.append("money", this.ruleForm.money);
          params.append("standard", this.ruleForm.standard);
          params.append("buy", this.ruleForm.buy);
          console.log(params);
          this.$api.post("/signing", params, r => {
            console.log(r);
          });
          alert("签约成功!");
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    }
  }
};
</script>

<style lang="scss" scoped>
.clearfix {
  span {
    display: block;
    float: left;
    line-height: 40px;
    text-align: left;
  }
  button {
    display: block;
    float: right;
  }
  &:after {
    content: "";
    display: block;
    clear: both;
  }
}

.sub-btn {
  button:first-child {
    display: block;
    float: left;
  }
  button:last-child {
    display: block;
    float: right;
  }
  &:after {
    content: "";
    display: block;
    clear: both;
  }
}
</style>
